package com.utils;

import com.data.ConnectedEdge;
import com.data.Node;

import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

/**
 * Created by IntelliJ IDEA. User: yt347 Date: 5/7/11 Time: 5:55 PM
 */
public class CommonUtils {
	/**
	 * Values: x1 y1 x2 y2 a1 b1 a2 b2......
	 * 
	 * @param values
	 * @return
	 */
	public static Set<ConnectedEdge> getEdgesFromString(String values) {
		StringTokenizer st = new StringTokenizer(values);
		int count = 0;
		double[] vals = new double[4];
		Set<ConnectedEdge> edges = new HashSet<ConnectedEdge>();
		while (st.hasMoreTokens()) {
			for (int i = 0; i < 4 && st.hasMoreTokens(); i++) {
				vals[i] = Double.parseDouble(st.nextToken().toString());
				count++;
			}
			if (count % 4 == 0) {
				edges.add(new ConnectedEdge(new Node(vals[0], vals[1]),
						new Node(vals[2], vals[3])));
			}
		}
		return edges;
	}
}
